import Api from "../../../../utils/http";

// pages/user/user/userCode/userCode.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    codeType: 1, //1 为身份二维码，2 为 开门二维码
    userinfo: null, //个人信息
    opencode:'',//开门二维码
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var codeType = options.codeType;
    if (codeType == 2) {
      wx.setNavigationBarTitle({
        title: '开门',
      })
      this.setData({
        codeType: 2
      })
    } else {
      wx.setNavigationBarTitle({
        title: '身份二维码',
      })
    }
    this.getUserInfn();
    this.getOpenCode();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  //开门我二维码
  getOpenCode: function () {
    var that = this;
    var uid = wx.getStorageSync('userid');
    var param = {
      uid: uid.id,
      user_type:uid.user_type
    }
    console.log(param)
    Api.ajax('/app/zindex/ewmCode',param).then(res=>{
      console.log(res)
      if (res.code==200) {
        that.setData({
          opencode:res.data
        })
        
      }
    })
  },
  //个人信息
  getUserInfn: function () {
    var that = this;
    var uid = wx.getStorageSync('userid');
    var param = {
      uid: uid.id,
      user_type: uid.user_type
    }
    console.log(param)
    Api.ajax('/app/Zpersonalcenter/userInfo', param).then(res => {
      console.log(res)
      if (res.code == 200) {
        that.setData({
          userinfo: res.data
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})